﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using SnowDAL;
using System.Data;
using Common.Expansion;

namespace Snow.Setting
{
    public partial class TimeSetting : System.Web.UI.Page
    {
        private UserDAL _dal = new UserDAL();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegTime_Click(object sender, EventArgs e)
        {
            int i = 0;
            lblMessage.Text = "0";
            var list = Get3WeekDate();
            foreach (DataRow row in _dal.QueryMyUser().Rows)
            {
                string date = GetRandomDate(list).ToShortDateString();
                _dal.UpdateMyUserRegTime(row["uid"].ToString(), date);
                lblMessage.Text = (i++).ToString();
            }

            Page.Alert("更新成功");
        }

        private DateTime GetRandomDate(List<DateTime> list)
        {
            Thread.Sleep(10);
            Random radom = new Random();
            int i = radom.Next(0, Get3WeekDate().Count - 1);
            return list[i];
        }

        private List<DateTime> Get3WeekDate()
        {
            List<DateTime> result = new List<DateTime>();
            DateTime now = DateTime.Now.Date;
            for (int i = 0; i < 21; i++)
                result.Add(now.AddDays(-i));
            return result; 
        }

        
    }
}